package cc.telecomdigital.tdstock.adapter;

import java.util.List;

import cc.telecomdigital.tdstock.R;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AHListItemAdapter extends BaseAdapter
{
	private LayoutInflater		minflater;
	private List<AHViewHolder>	list;

	public AHListItemAdapter(LayoutInflater inflater, List<AHViewHolder> list)
	{
		super();
		this.minflater = inflater;
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position < this.list.size() ? this.list.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return position < this.list.size() ? this.list.get(position).id : -1l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		AHViewHolder commHolder = null;
		if (convertView == null)
		{
			convertView = minflater.inflate(R.layout.ah_list_item, null);
			commHolder = new AHViewHolder();
			commHolder.itemName = (TextView) convertView
					.findViewById(R.id.ah_item_name);
			commHolder.column1 = (TextView) convertView
					.findViewById(R.id.ah_column_1);
			commHolder.column2 = (TextView) convertView
					.findViewById(R.id.ah_column_2);
			commHolder.column3 = (TextView) convertView
					.findViewById(R.id.ah_column_3);

			//synchronize with iphone
			commHolder.itemName.setTextColor(Color.BLACK);
			commHolder.column1.setTextColor(Color.BLACK);
			commHolder.column2.setTextColor(Color.BLACK);
			commHolder.column3.setTextColor(Color.BLACK);
			convertView.setDrawingCacheBackgroundColor(Color.WHITE);

			//synchronize with iphone

			convertView.setTag(commHolder);
		}
		else
		{
			commHolder = (AHViewHolder) convertView.getTag();
		}
		commHolder.itemName.setText(this.list.get(position).itemName
				.getText());
		commHolder.column1.setText(this.list.get(position).column1.getText());
		commHolder.column2.setText(this.list.get(position).column2.getText());
		commHolder.column3.setText(this.list.get(position).column3.getText());
		return convertView;
	}

}
